package com.itwn.email.producer.d_direct;

import org.assertj.core.util.Lists;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

/**
 * 路由模式
 * 1、通过交换机发送消息,且指定路由key
 * 2、交换机 - 队列 - 路由key
 *      交换机： direct.exchange
 *      队列： direct.queue1   路由key： a
 *      队列： direct.queue2   路由key： b
 */
@Configuration
public class DirectConfig {
    public static final String DIRECT_EXCHANGE = "direct.exchange";
    public static final String DIRECT_QUEUE1 = "direct.queue1";
    public static final String DIRECT_QUEUE2 = "direct.queue2";

    //1、创建交换机： direct.exchange
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    //2、创建队列： direct.queue1
    @Bean
    public Queue directQueue1(){
        return new Queue(DIRECT_QUEUE1, true,false, false);
    }

    //3、创建队列： direct.queue2
    @Bean
    public Queue directQueue2(){
        return new Queue(DIRECT_QUEUE2, true,false, false);
    }

    //4、绑定队列（direct.queue1）到交换机（direct.exchange）
    @Bean
    public Binding bindingDirectExchangeAndQueue1(Queue directQueue1,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue1).to(directExchange).with("a");
    }

    //5、绑定队列（direct.queue2）到交换机（direct.exchange）
    @Bean
    public Binding bindingDirectExchangeAndQueue2(Queue directQueue2,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue2)
                .to(directExchange).with("b");
    }

}
